import 'package:flutter/material.dart';

class ViewUtils {
  static Future<String> showDateTimePicker(BuildContext context,
      {bool isSelectRange = false}) async {
    DateTime nowTime = DateTime.now();
    String dateSelectText = "";
    if (!isSelectRange) {
      DateTime? time = await showDatePicker(
          context: context,
          initialDate: nowTime,
          firstDate: nowTime,
          lastDate: DateTime(nowTime.year + 1));
      if (time != null) {
        return dateSelectText = time.toString().split(" ")[0];
      }
    } else {
      //显示时间选择器
      DateTimeRange? selectTimeRange = await showDateRangePicker(
        //语言环境
        locale: const Locale("zh", "CH"),
        context: context,
        firstDate: nowTime,
        lastDate: DateTime(DateTime.now().year + 1),
        saveText: "保存",
      );
      //结果

      if (selectTimeRange != null) {
        dateSelectText = selectTimeRange.start.toString().split(" ")[0] +
            " - " +
            selectTimeRange.end.toString().split(" ")[0];
      }
    }

    return dateSelectText;
  }
}
    //获取当前的时间
    // DateTime start = DateTime.now();
    // //在当前的时间上多添加4天
    // DateTime end = DateTime(start.year, start.month, start.day + 4);

      //开始时间
      // firstDate: DateTime(2022, 1),
      // //结束时间
      // lastDate: DateTime(2024, 1),
      // dateSelectText = selectTimeRange.toString();
      // //选择结果中的开始时间
      // DateTime selectStart = selectTimeRange.start;
      // //选择结果中的结束时间
      // DateTime selectEnd = selectTimeRange.end;
      //初始的时间范围选择
      // initialDateRange: DateTimeRange(start: start, end: end)